package com.user.servlet;

import com.user.entity.BookInfo;
import com.user.entity.Users;
import com.user.service.IUserService;
import com.user.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "UserBorrowBooksServlet", value = "/UserBorrowBooksServlet")
public class UserBorrowBooksServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String username = request.getParameter("username");
        int bookid = Integer.parseInt(request.getParameter("bookid"));
        IUserService userService = new UserServiceImpl();
        boolean result = userService.userBorrowBooks(new Users(username, "0"), new BookInfo(bookid));

        request.setAttribute("msg", "借阅成功！");
        request.getRequestDispatcher("/BookListServlet").forward(request, response);


    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
